#include <iostream>
#include <fstream>
#include <math.h>
using namespace std;

int main() {
    ifstream ifile("input.txt");
    int a,b;
    ifile >> a >> b;
    ifile.close();

    int res = 0;
    int max = sqrt(a) + 1;

    if (b % a != 0)
        res += a;

    for (int i = 2; i <= max; ++i) {
        if (a % i == 0) {
            if (b % i != 0)
                res += i;
            //max /= i;
        }
    }

    ofstream ofile("output.txt");
    ofile << res;
    ofile.close();
    return 0;
}
